package com.hczt.fire.server.backend.sys.controller;

import com.hczt.fire.entity.sys.SysPermission;
import com.hczt.fire.entity.sys.SysUser;
import com.hczt.fire.server.backend.sys.service.SysPermissionService;
import com.hczt.fire.server.common.util.ShiroUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author marvin.ma
 * @create 2017-10-18 7:43
 * @desc ${DESCRIPTION}
 **/
@Controller
public class IndexController {

    private static final Logger log = LoggerFactory.getLogger(IndexController.class);

    @Resource
    private SysPermissionService sysPermissionService;
    /**
     * 定义welcome-file-list页面
     * @return
     */
    @GetMapping("")
    public String toIndex() {
        return "redirect:/admin/index";
    }

    /**
     * 首页
     */
    @GetMapping("admin/index")
    public String index(ModelMap modelMap) {
        //从shiro的session中获取user
        SysUser sysUser = ShiroUtils.getUserEntity();

        List<SysPermission> menuList = sysPermissionService.findByUserId(sysUser.getId());
        //通过model传到页面
        modelMap.addAttribute("menuList", menuList);
        log.info("------进入首页-------");
        return "admin/index";
    }

    /**
     * 欢迎页
     * @return
     */
    @GetMapping(value = "/admin/welcome")
    public String welcome(){
        log.info("------进入欢迎页-------");
        return "admin/welcome";
    }

    /**
     * 未授权页面
     * @return
     */
    @GetMapping(value = "/admin/403")
    public String unauthorized(){
        log.info("------没有权限-------");
        return "admin/common/403";
    }
}
